package createobject;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import environment.Simulation;

public abstract class Factory {

    /**
     * @param sim Simulation
     * @param modelFile File
     */
    public void loadModel(Simulation sim, File modelFile) {
        try {
            Scanner input = new Scanner(modelFile);
            while (input.hasNext()) {
                Scanner line = new Scanner(input.nextLine());
                if (line.hasNext()) {
                    String type = line.next();
                    createObject(sim, line, type);
                }
            }
            input.close();
        } catch (FileNotFoundException e) {
            // should not happen because File came from user selection
            e.printStackTrace();
        }
    }

    /**
     * @param sim Simulation
     * @param line line of read text
     * @param type type of object to create
     */
    abstract void createObject (Simulation sim, Scanner line, String type);
}
